package com.zyy.admin.controller;

import com.zyy.admin.entity.LabelRuleTemplate;
import com.zyy.admin.service.DataService;
import com.zyy.api.pojo.LabelInfo;
import com.zyy.api.pojo.LabelNewsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 *@author zhangyangyang
 *@createTime 2023419 18:36
 *@description 常用服务-业务逻辑接口
 */
@RequestMapping("data")
@RestController
@Validated
//@PreAuthorize("hasAuthority('ROLE_USER')")
public class DataController {

    @Autowired
    private DataService dataService;

    @GetMapping("getTemplateByUser/{userId}")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_USER)")
    List<LabelRuleTemplate> getTemplateByUser(@PathVariable("userId") Integer userID){
        return dataService.getTemplateByUser(userID);
    }

    @GetMapping("getAvailableTemplate/{userId}")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_USER)")
    LabelRuleTemplate getAvailableTemplate(@PathVariable("userId") Integer userId){
        return dataService.getAvailableTemplate(userId);
    }

    @PostMapping("analysisFundLabel")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_USER)")
    List<LabelInfo> analysisFundLabel(@Valid @RequestBody LabelNewsInfo info) {
        return dataService.analysisFundLabel(info);
    }

    @PostMapping("getAllTypeLabel")
    @ResponseBody
    @PreAuthorize("hasAuthority(T(com.zyy.admin.config.security.PermissionEnum).ROLE_USER)")
    public List<LabelInfo> getAllTypeLabel(@Valid @RequestBody LabelNewsInfo info) {
        return dataService.getAllTypeLabel(info);
    }
}
